#coding=utf-8
#import libs 
import sys
import os
from   os.path import abspath, dirname
sys.path.insert(0,abspath(dirname(__file__)))
import AutoPack_cmd
import AutoPack_sty
import Fun
import EXUIControl
EXUIControl.FunLib = Fun
EXUIControl.G_ExeDir = Fun.G_ExeDir
EXUIControl.G_ResDir = Fun.G_ResDir
import tkinter
from   tkinter import *
import tkinter.ttk
import tkinter.font
from   PIL import Image,ImageTk

#Add your Varial Here: (Keep This Line of comments)
#Define UI Class
class  AutoPack:
    def __init__(self,root,isTKroot = True,params=None):
        uiName = Fun.GetUIName(root,self.__class__.__name__)
        self.uiName = uiName
        Fun.Register(uiName,'UIClass',self)
        self.root = root
        self.configure_event = None
        self.isTKroot = isTKroot
        self.firstRun = True
        self.rootZoomed = False
        Fun.G_UIParamsDictionary[uiName]=params
        Fun.G_UICommandDictionary[uiName]=AutoPack_cmd
        Fun.Register(uiName,'root',root)
        style = AutoPack_sty.SetupStyle(isTKroot)
        self.UIJsonString = '{"Version": "1.0.0", "UIName": "AutoPack", "Description": "", "WindowSize": [1223, 1260], "WindowPosition": "Center", "WindowHide": false, "WindowResizable": true, "WindowTitle": "自动打包", "DarkMode": false, "BorderWidth": 0, "BorderColor": "#ffffff", "DropTitle": false, "DragWindow": false, "MinSize": [0, 0], "ResolutionScaling": false, "PopupDebugDialog": false, "TransparentColor": null, "RootTransparency": 255, "ICOFile": "D:/Project/AutoPack/ico.png", "ICOMode": "File", "WinState": 1, "WinTopMost": false, "BGColor": "#4FC1E9", "GroupList": {}, "WidgetList": [{"Type": "Form", "Index": 1, "AliasName": "Form_1", "BGColor": "#4FC1E9", "Size": [1223, 1260], "PlaceInfo": null, "EventList": {"Control-d": "Form_1_onControl_d", "Load": "Form_1_onLoad", "Control-f": "Form_1_onControl_f", "Control-g": "Form_1_onControl_g"}}, {"Type": "Label", "Index": 8, "AliasName": "Label_1", "ParentName": "Form_1", "PlaceInfo": [16, 29, 198, 55, "nw", true, true], "Visible": true, "Size": [198, 55], "BGColor": "#4FC1E9", "Text": "项目目录路径", "FGColor": "#000000", "Anchor": "e", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0]}, {"Type": "Label", "Index": 10, "AliasName": "Label_2", "ParentName": "Form_1", "PlaceInfo": [22, 131, 192, 55, "nw", true, true], "Visible": true, "Size": [192, 55], "BGColor": "#4FC1E9", "Text": "项目入口文件", "FGColor": "#000000", "Anchor": "e", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0]}, {"Type": "Label", "Index": 13, "AliasName": "Label_3", "ParentName": "Form_1", "PlaceInfo": [614, 29, 244, 55, "nw", true, true], "Visible": true, "Size": [244, 55], "BGColor": "#4FC1E9", "Text": "pyd文件存储目录", "FGColor": "#000000", "Anchor": "e", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0]}, {"Type": "Label", "Index": 40, "AliasName": "Label_4", "ParentName": "Form_1", "PlaceInfo": [36, 845, 244, 55, "nw", true, true], "Visible": true, "Size": [244, 55], "BGColor": "#4FC1E9", "Text": "信息显示", "FGColor": "#000000", "Anchor": "w", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0]}, {"Type": "Label", "Index": 51, "AliasName": "Label_5", "ParentName": "Form_1", "PlaceInfo": [716, 161, 284, 55, "nw", true, true], "Visible": true, "Size": [284, 55], "BGColor": "#4FC1E9", "Text": "pyd不保持原目录", "FGColor": "#000000", "Anchor": "e", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0]}, {"Type": "Label", "Index": 53, "AliasName": "Label_6", "ParentName": "Form_1", "PlaceInfo": [709, 101, 291, 58, "nw", true, true], "Visible": true, "Size": [291, 58], "BGColor": "#4FC1E9", "Text": "不重新编绎pyd", "FGColor": "#000000", "Anchor": "e", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0]}, {"Type": "Entry", "Index": 9, "AliasName": "project_dir", "ParentName": "Form_1", "PlaceInfo": [230, 32, 253, 50, "nw", true, true], "Visible": true, "Size": [253, 50], "BGColor": "#4FC1E9", "BGColor_ReadOnly": "#EFEFEF", "FGColor": "#000000", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "InnerBorderType": "borderline", "InnerBorderWidth": 1, "InnerBorderColor": "#5D9CEC", "InnerBorderDash": [1, 1], "TipFGColor": "#888888", "Relief": "solid", "InnserspaceX": 1, "EventList": {}}, {"Type": "Entry", "Index": 11, "AliasName": "main_file_path", "ParentName": "Form_1", "PlaceInfo": [230, 138, 253, 50, "nw", true, true], "Visible": true, "Size": [253, 50], "BGColor": "#4FC1E9", "BGColor_ReadOnly": "#EFEFEF", "FGColor": "#000000", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "InnerBorderType": "borderline", "InnerBorderWidth": 1, "InnerBorderColor": "#5D9CEC", "InnerBorderDash": [1, 1], "TipFGColor": "#888888", "Relief": "solid", "InnserspaceX": 1, "EventList": {}}, {"Type": "Entry", "Index": 16, "AliasName": "pyd_dir", "ParentName": "Form_1", "PlaceInfo": [867, 33, 253, 50, "nw", true, true], "Visible": true, "Size": [253, 50], "BGColor": "#4FC1E9", "BGColor_ReadOnly": "#EFEFEF", "FGColor": "#000000", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "InnerBorderType": "borderline", "InnerBorderWidth": 1, "InnerBorderColor": "#5D9CEC", "InnerBorderDash": [1, 1], "TipFGColor": "#888888", "Relief": "solid", "InnserspaceX": 1, "EventList": {}}, {"Type": "ListView", "Index": 12, "AliasName": "table", "ParentName": "Form_1", "PlaceInfo": [26, 227, 1166, 410, "nw", true, true], "Visible": true, "Size": [1166, 410], "SelectMode": "EXTENDED", "RowHeight": 45, "RowLine": false, "ColLine": false, "LineColor": "#000000", "LineWidth": 1, "Relief": "raised", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "TagList": [["normal", "Microsoft YaHei UI", 20, "normal", "roman", 0, 0, "#FFFFFF"]], "ColumnList": [["序号", "center", 60, false], ["py文件路径", "w", 600, false], ["pyd是否存在", "w", 485, false]], "EventList": {"Button-3": "table_onButton3"}, "ScrollBarList": [false, true]}, {"Type": "Button", "Index": 17, "AliasName": "项目目录浏览", "ParentName": "Form_1", "PlaceInfo": [498, 31, 100, 53, "nw", true, true], "Visible": true, "Size": [100, 53], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "浏览", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "项目目录浏览_onCommand"}}, {"Type": "Button", "Index": 18, "AliasName": "项目入口浏览", "ParentName": "Form_1", "PlaceInfo": [499, 138, 100, 53, "nw", true, true], "Visible": true, "Size": [100, 53], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "浏览", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "项目入口浏览_onCommand"}}, {"Type": "Button", "Index": 19, "AliasName": "pyd文件浏览", "ParentName": "Form_1", "PlaceInfo": [1098, 30, 100, 53, "nw", true, true], "Visible": true, "Size": [100, 53], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "浏览", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "pyd文件浏览_onCommand"}}, {"Type": "Button", "Index": 36, "AliasName": "获取py", "ParentName": "Form_1", "PlaceInfo": [26, 665, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "获取py文件", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "获取py_onCommand"}}, {"Type": "Button", "Index": 37, "AliasName": "nuitka打包", "ParentName": "Form_1", "PlaceInfo": [26, 752, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "nuitka打包", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "nuitka打包_onCommand"}}, {"Type": "Button", "Index": 39, "AliasName": "保存设置", "ParentName": "Form_1", "PlaceInfo": [786, 665, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "保存设置", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "保存设置_onCommand", "Double-Button-1": "保存设置_onDoubleButton1", "Button-3": "保存设置_onButton3"}}, {"Type": "Button", "Index": 48, "AliasName": "clean", "ParentName": "Form_1", "PlaceInfo": [279, 752, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "清理垃圾", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "clean_onCommand"}}, {"Type": "Button", "Index": 55, "AliasName": "复制pyd目录", "ParentName": "Form_1", "PlaceInfo": [1039, 751, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "复制pyd", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "复制pyd目录_onCommand"}}, {"Type": "Button", "Index": 56, "AliasName": "load_option", "ParentName": "Form_1", "PlaceInfo": [1040, 665, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "读取设置", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "load_option_onCommand"}}, {"Type": "Button", "Index": 57, "AliasName": "生成打包命令", "ParentName": "Form_1", "PlaceInfo": [785, 752, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "生成命令", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "生成打包命令_onCommand"}}, {"Type": "Button", "Index": 58, "AliasName": "单个打包pyc", "ParentName": "Form_1", "PlaceInfo": [533, 665, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "打包pyc", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "单个打包pyc_onCommand"}}, {"Type": "Button", "Index": 59, "AliasName": "单个nuitka", "ParentName": "Form_1", "PlaceInfo": [279, 663, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "单个nuitka", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "单个nuitka_onCommand"}}, {"Type": "Button", "Index": 60, "AliasName": "refresh", "ParentName": "Form_1", "PlaceInfo": [533, 751, 150, 50, "nw", true, true], "Visible": true, "Size": [150, 50], "BGColor": "#4A89DC", "ActiveBGColor": "#48CFAD", "Text": "更新信息", "FGColor": "#FFFFFF", "ActiveFGColor": "#5D9CEC", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "Relief": "raised", "EventList": {"Command": "refresh_onCommand"}}, {"Type": "Text", "Index": 41, "AliasName": "info_output", "ParentName": "Form_1", "PlaceInfo": [26, 893, 1165, 350, "nw", true, true], "Visible": true, "Size": [1165, 350], "BGColor": "#AC92EC", "AutoWrap": true, "FGColor": "#333333", "Font": ["Microsoft YaHei UI", 18, "normal", "roman", 0, 0], "TagList": [["normal", "Microsoft YaHei UI", 18, "normal", "roman", 0, 0, "#333333"]], "Relief": "sunken", "ScrollBarList": [false, true]}, {"Type": "SwitchButton", "Index": 49, "AliasName": "is_keep", "ParentName": "Form_1", "PlaceInfo": [1035, 173, 93, 30, "nw", true, true], "Visible": true, "Size": [93, 30], "Shape": "circular", "BGColor_Off": "#5D9CEC", "Text_Off": "", "FGColor_Off": "#FFFFFF", "BtnColor_Off": "#FFFFFF", "BGColor_On": "#AC92EC", "Text_On": "", "FGColor_On": "#FFFFFF", "BtnColor_On": "#FFFFFF", "Font": ["Microsoft YaHei UI", 9, "normal", "roman", 0, 0], "Value": false, "SwitchMode": "0", "EventList": {"Switch": "is_keep_onSwitch"}}, {"Type": "SwitchButton", "Index": 54, "AliasName": "recompile", "ParentName": "Form_1", "PlaceInfo": [1035, 120, 93, 30, "nw", true, true], "Visible": true, "Size": [93, 30], "Shape": "circular", "BGColor_Off": "#5D9CEC", "Text_Off": "", "FGColor_Off": "#FFFFFF", "BtnColor_Off": "#FFFFFF", "BGColor_On": "#AC92EC", "Text_On": "", "FGColor_On": "#FFFFFF", "BtnColor_On": "#FFFFFF", "Font": ["Microsoft YaHei UI", 9, "normal", "roman", 0, 0], "Value": false, "SwitchMode": "0", "EventList": {"Switch": "recompile_onSwitch"}}]}'
        Form_1 = Fun.CreateUIFormJson(uiName,root,isTKroot,style,self.UIJsonString)
        #Inital all element's Data 
        Fun.InitElementData(uiName)
        #Call Form_1's OnLoad Function
        Fun.RunForm1_CallBack(uiName,"Load",AutoPack_cmd.Form_1_onLoad)
        #Add Some Logic Code Here: (Keep This Line of comments)



        #Exit Application: (Keep This Line of comments)
        if self.isTKroot == True and Fun.GetElement(self.uiName,"root"):
            self.root.protocol('WM_DELETE_WINDOW', self.Exit)
            self.root.bind('<Configure>', self.Configure)
            if self.rootZoomed == True and isinstance(self.root,tkinter.Tk) == True:
                self.root.state("zoomed")
                Fun.SetUIState(uiName,"zoomed")
                self.rootZoomed = False
            
    def GetRootSize(self):
        return Fun.GetUIRootSize(self.uiName)
    def GetAllElement(self):
        return Fun.G_UIElementDictionary[self.uiName]
    def Escape(self,event):
        if Fun.AskBox('提示','确定退出程序？') == True:
            self.Exit()
    def Exit(self):
        if self.isTKroot == True:
            Fun.DestroyUI(self.uiName,0,'')

    def Configure(self,event):
        Form_1 = Fun.GetElement(self.uiName,'Form_1')
        if Form_1 == event.widget:
            Fun.ReDrawCanvasRecord(self.uiName)
        if self.root == event.widget and (self.configure_event is None or self.configure_event[2]!= event.width or self.configure_event[3]!= event.height):
            uiName = self.uiName
            self.configure_event = [event.x,event.y,event.width,event.height]
            Fun.ResizeRoot(self.uiName,self.root,event)
            Fun.ResizeAllChart(self.uiName)
            pass
#Create the root of tkinter 
if  __name__ == '__main__':
    Fun.RunApplication(AutoPack)
